package com.garbagecan.cachestudy.ehcache;

import java.lang.System;
import java.net.URL;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class TestPersistenceCache {

	public static void main(String[] args) throws Exception {
//		write();
		read();
	}

	private static void write() {
		URL url = CacheManagerExample.class.getResource("ehcache.xml");
		CacheManager cacheManager = new CacheManager(url);
		Cache cache = cacheManager.getCache("persistenceCache");
		for (int i = 0; i < 10000; i++) {
			cache.put(new Element("key_" + i, "value_" + i));
		}
		System.out.println(cache.get("key_" + 0));
		cacheManager.shutdown();
	}

	private static void read() {
		URL url = CacheManagerExample.class.getResource("ehcache.xml");
		CacheManager cacheManager = new CacheManager(url);
		Cache cache = cacheManager.getCache("persistenceCache");
		System.out.println(cache.get("key_" + 0));
		cacheManager.shutdown();
	}

}
